package com.example.demo.controller;

import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/users")
public class UserEController {

    @Autowired
    private UserService userService;

    @PostMapping("/import")
    public String importExcel(@RequestParam("file") MultipartFile file) {

        try {
            userService.importExcel(file);
            return "Excel file imported successfully!";
        } catch (Exception e) {
            e.printStackTrace();
            return "Failed to import Excel file: " + e.getMessage();
        }
    }
    @GetMapping("/export")
    public void exportToExcel(HttpServletResponse response) throws IOException {
        userService.exportToExcel(response);
    }
}
